package com.android.zweibo.util;

import weibo4android.Weibo;
import weibo4android.WeiboException;
import weibo4android.http.AccessToken;
import weibo4android.http.RequestToken;
/**
 * 授权认证工具类
 * @author zxf
 *
 */
public class AuthUtil {
	
	private static Weibo weibo;
	private static RequestToken requestToken;
	static{
		System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
		System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
		
		weibo = new Weibo();
	}
	
	
	
	/**
	 * 获取授权的URL
	 * @return
	 */
	public static String getAuthorizationURL() {
		try {
			requestToken = weibo.getOAuthRequestToken();
			
			return requestToken.getAuthenticationURL();
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	
	/**
	 * 获取AccessToken
	 * @param pin
	 * @return
	 */
	public static AccessToken getAccessToken(String pin) {
		try {
			AccessToken accessToken = requestToken.getAccessToken(pin);		
			return accessToken;
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		
		return null;
	}

}
